package ControlLayer;
import java.util.ArrayList;

import ModelLayer.*; //import all Class' in ModelLayer

 /* Controller class for the DVD collection
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * @revised version English (Ab)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class DVDCtr
{
    //declare instance variables to reference containers
    private DVDContainer dvdCon;
    private int id;
    private static DVDCtr instance;

    /**
     * Constructor for objects of class DVDCtr
     */
    private DVDCtr()
    {
        dvdCon = DVDContainer.getInstance();
        id = 0;
    }
    
    public static DVDCtr getInstance()
    {
        if(instance == null)
        {
            instance = new DVDCtr();
        }
        return instance;
    }
    //Dummy implementation: after implementing the model layer 
    //objects of class DVD are to be returned, not String
    public DVD findDVD(int no)
    {
       DVD dvd = dvdCon.findDVD(no);
       return dvd; 
    }
    
    //Dummy implementation: more parameters are probaly to added
    public void createDVD(String title, String publisher, String releasedate)
    {       
        id++;  
        DVD dvd = new DVD(id, title, publisher, releasedate);
        dvdCon.addDVD(dvd);
        
    }
    
    public void updateDVD(int idDVD, String title, String publisher, String releasedate)
    {
        dvdCon.UpdateDVD(idDVD, title, publisher, releasedate);
    }
    
    public int getID()
    {
        return id;
    }
    
    public void setID(int id)
    {
        this.id = id;
    }
    
    public void deleteDVD(int id)
    {
        dvdCon.deleteDVD(id);
        //search for the dvd and delete the object from the container
    }
    
    public void createCopy(int id, String acdate, int acprice)
    {
        //create a copy of the specified dvd and add it to the dvd
        DVD dvd = dvdCon.findDVD(id);
        dvd.createCopy(acdate, acprice);
    }    
    
    public void deleteCopy(int idDVD, int idCOPY)
    {
        findDVD(idDVD).deleteCopy(idCOPY);
    }
    
    public void updateCopy(int idDVD, int idCOPY, String acDate, int acPrice)
    {
        findDVD(idDVD).UpdateCopy(idCOPY, acDate, acPrice);
    }
    
    public void listAllDvd()
    {
          //returns a list of all dvds         
          dvdCon.printDetailDVD();
    }
    
    public void listAllDVDAndCopies()
    {
        //returns a list of all dvds and their associated copies
       dvdCon.printDeatilDVDandCopies();              
    }
    
    public int getSize()
    {
        return dvdCon.getSize();
    }
    
    public Copy findCopy(int no1, int no2)
    {
        DVD dvd = findDVD(no1);
        return dvd.findCopy(no2);
    }    
    
    public int getSerieNoCopy(int no)
    {
        return dvdCon.getSerieNoCopy(no);
        
    }
}
